import 'package:flutter/material.dart';
import 'package:flutter_syt/api/api.dart';
import 'package:flutter_syt/datas/feedback_item.dart';
import 'package:flutter_syt/domain/mine/feedback_list_item.dart';
import 'package:flutter_syt/generated/l10n.dart';
import 'package:flutter_syt/routes.all.dart';
import 'package:flutter_syt/theme/font_styles.dart';
import 'package:flutter_syt/utils/click_utils.dart';
import 'package:flutter_syt/widgets/normal_table.dart';
import 'package:yyy_route_annotation/yyy_route_annotation.dart';

@RoutePage(name: "feedbackListPage")
class FeedbackListPage extends StatefulWidget {
  const FeedbackListPage();

  @override
  _FeedbackListPageState createState() => _FeedbackListPageState();
}

class _FeedbackListPageState extends State<FeedbackListPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          S.of(context).feedback_history,
          style: FontStyles.headerTextStyle_18.copyWith(
            fontWeight: FontWeight.w500,
          ),
        ),
      ),
      body: NormalTableView<FeedbackItem>(
        pageSize: (p0) {
          return 10;
        },
        padding: EdgeInsets.symmetric(horizontal: 15),
        itemBuilder: (ctx, item) {
          return GestureDetector(
            child: Container(
              child: FeedbackListItem(item),
            ),
            onTap: ClickUtils.debounce(() {
              RouteManager.push(
                  context, RoutMapping.feedbackDetail(item.id, true));
            }),
          );
        },
        getData: (page) async {
          var json = await API.shared.feedback.list(page, size: 10);
          return json;
        },
      ),
    );
  }
}
